﻿using System;
using System.ComponentModel;
using MugenMvvmToolkit.Interfaces.Views;

namespace MugenMvvmToolkitTest.TestModels
{
    public class TestDialogView : IChildWindowView
    {
        #region Properties

        public bool IsShow { get; set; }

        public bool IsClose { get; set; }

        #endregion

        #region Implementation of IView

        /// <summary>
        ///     Gets or sets the data context of <see cref="IView" />.
        /// </summary>
        public object DataContext { get; set; }

        #endregion

        #region Implementation of IWindowViewBase

        /// <summary>
        ///     Shows dialog as a window.
        /// </summary>
        public void Show()
        {
            IsShow = true;
        }

        /// <summary>
        ///     Closes the dialog.
        /// </summary>
        public void Close()
        {
            var cancelEventArgs = new CancelEventArgs(false);
            OnClosing(cancelEventArgs);
            if (cancelEventArgs.Cancel) return;
            IsClose = true;
        }

        #endregion

        #region Implementation of IChildWindowView

        public event EventHandler<CancelEventArgs> Closing;

        protected virtual void OnClosing(CancelEventArgs e)
        {
            EventHandler<CancelEventArgs> handler = Closing;
            if (handler != null) handler(this, e);
        }

        #endregion
    }
}